package com.hmjk.health.setting.system;

import com.hmjk.health.HealthApp;
import com.hmjk.health.R;
import com.hmjk.health.views.SwitchButton;
import com.hmjk.health.views.SwitchButton.OnChangeListener;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class NewMessageNotificationActivity extends Activity implements OnClickListener, OnChangeListener{
	private final String TAG = NewMessageNotificationActivity.class.getSimpleName();
	private HealthApp mApp = null;
	private boolean isOnMsg = false, isOnSound = false, isOnVib = false;
	private SwitchButton switchMsg = null, switchSound = null, switchVib = null;
	
	private void logd(String info){
		Log.d(TAG,info);
	}
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		logd("onCreate");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.new_message_notice);
        
        mApp = (HealthApp) this.getApplication();
        
        ImageButton back = (ImageButton) findViewById(R.id.back);
        back.setOnClickListener(this);
        switchMsg = (SwitchButton)findViewById(R.id.receive_switch);
        switchMsg.setOnChangeListener(this);
        isOnMsg = mApp.getMQTTMsgOn();
        switchMsg.setFlage(isOnMsg);
        
        switchSound = (SwitchButton)findViewById(R.id.sound_switch);
        switchSound.setOnChangeListener(this);
        isOnSound = mApp.getMQTTSoundOn();
        switchSound.setFlage(isOnSound);
        
        switchVib = (SwitchButton)findViewById(R.id.vibrator_switch);
        switchVib.setOnChangeListener(this);
        isOnVib = mApp.getMQTTVibOn();
        switchVib.setFlage(isOnVib);
        
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.back:{
			finish();
		}break;
		
		}
	}


	@Override
	public void onChange(SwitchButton sb, boolean state) {
		// TODO Auto-generated method stub
		switch(sb.getId()){
		case R.id.receive_switch:{
			mApp.setMQTTMsgOn(state);
		}break;
		
		case R.id.sound_switch:{
			mApp.setMQTTSoundOn(state);
		}break;
		
		case R.id.vibrator_switch:{
			mApp.setMQTTVibOn(state);
		}break;
		
		}
	}

}
